import os
import pandas as pd

def list_filenames():
    # 指定目录路径
    directory = "output_images/运输途中"
    
    # 确保目录存在
    if not os.path.exists(directory):
        print(f"目录 {directory} 不存在")
        return
    
    # 获取所有文件名（不包含后缀）
    filenames = []
    for filename in os.listdir(directory):
        # 获取文件名（不包含后缀）
        name_without_ext = os.path.splitext(filename)[0]
        filenames.append(name_without_ext)
    
    # 创建DataFrame
    df = pd.DataFrame(filenames, columns=['fileName'])
    
    # 保存为Excel文件
    excel_file = "file_names.xlsx"
    df.to_excel(excel_file, index=False)
    
    print(f"已将 {len(filenames)} 个文件名写入到 {excel_file}")

if __name__ == "__main__":
    list_filenames() 